package com.guoguo.utils.nowpay;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateHelper {
	
	public static String transferToYYYY(Long time){
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sf.format(new Date(time));
	}

	/**
	 * 获取到今天23点59分59秒剩余时间
	 * @return
	 */
	public static Integer getTodayLastTime() {
		Calendar cal = Calendar.getInstance();  
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return Integer.valueOf("" + (cal.getTime().getTime()-System.currentTimeMillis())/1000);
	}
	
	/**
	 * 获取今天23点59分59秒
	 * @return
	 */
	public static Long getTodayEndTime() {
		Calendar cal = Calendar.getInstance();  
		cal.set(Calendar.HOUR_OF_DAY, 23);
		cal.set(Calendar.MINUTE, 59);
		cal.set(Calendar.SECOND, 59);
		return cal.getTime().getTime();
	}
	
	/**
	 * 获取今天0点0分0秒
	 * @return
	 */
	public static Long getTodayBeginTime() {
		Calendar cal = Calendar.getInstance();  
		cal.set(Calendar.HOUR_OF_DAY, 0);
		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		return cal.getTime().getTime();
	}

	/**
	 * 获取到这周天23点59分59秒剩余时间
	 * @return
	 */
	public static Integer getWeekLastTime() {
		Calendar cal =Calendar.getInstance();
		Integer weekDay = getMonDayTime();
		cal.setFirstDayOfWeek(Calendar.MONDAY);
		cal.set(Calendar.HOUR_OF_DAY,23);
		cal.set(Calendar.MINUTE,59);
		cal.set(Calendar.SECOND,59);
		return Integer.valueOf("" + (cal.getTime().getTime() - System.currentTimeMillis())/1000 )  + weekDay*86400;
	}
	
	/**
	 * 获取到这周一0点0分0秒时间
	 * @return
	 */
	public static Long getWeekEndTime() {
		Calendar cal =Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
		cal.set(Calendar.HOUR_OF_DAY,23);
		cal.set(Calendar.MINUTE,59);
		cal.set(Calendar.SECOND,59);
		cal.add(Calendar.WEEK_OF_YEAR, 1);
		return cal.getTime().getTime();
	}
	
	/**
	 * 获取到这周末23点59分59秒
	 * @return
	 */
	public static Long getWeekBeginTime() {
		Calendar cal =Calendar.getInstance();
		cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		cal.set(Calendar.HOUR_OF_DAY,0);
		cal.set(Calendar.MINUTE,0);
		cal.set(Calendar.SECOND,0);
		return cal.getTime().getTime();
	}
	
	/**
	 * 获取到本周剩余几天
	 * @return
	 */
	public static Integer getMonDayTime() {
		Calendar cal =Calendar.getInstance();
		cal.setFirstDayOfWeek(Calendar.MONDAY);
		Integer weekDay = cal.get(Calendar.DAY_OF_WEEK);
		if(weekDay == 1){
			return 0;
		}else{
			return  8 - weekDay;
		}
	}
	
}
